package cn.juque.datapipeline.helper;

import cn.hutool.extra.spring.SpringUtil;
import cn.juque.common.exception.AppException;
import cn.juque.datapipeline.api.enums.DataPipelineMsgEnum;
import cn.juque.datapipeline.api.enums.DbEnum;
import cn.juque.datapipeline.datasource.AbstractDatasource;
import cn.juque.datapipeline.entity.DatabaseInfo;
import org.springframework.stereotype.Component;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>DatasourceHelper</li>
 * </ul>
 * @date 2023-04-04 22:04:37
 **/
@Component("datasourceHelper")
public class DatasourceHelper {

    /**
     * 创建驱动
     *
     * @param databaseInfo 驱动信息
     * @return 驱动
     */
    public AbstractDatasource render(DatabaseInfo databaseInfo) {
        DbEnum dbEnum = DbEnum.forEnum(databaseInfo.getDbType());
        switch (dbEnum) {
            case MYSQL:
                return SpringUtil.getBean("mysqlDatasource");
            case ORACLE:
                return SpringUtil.getBean("oracleDatasource");
            default:
                break;
        }
        throw new AppException(DataPipelineMsgEnum.DB_TYPE_MISSING);
    }
}
